package com.meevle.commands {
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.meevle.business.SetDelegate;
	import com.meevle.error.ErrorHandler;
	import com.meevle.events.GetSetListEvent;
	import com.meevle.model.ViewModelLocator;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.IResponder;
	import mx.rpc.events.FaultEvent;
	
	public class GetSetListCommand implements ICommand, IResponder {
		
		public function GetSetListCommand() {
			
		}
		
		// ICommand interface method
		public function execute(event:CairngormEvent):void {
			var getSetListEvent:GetSetListEvent = event as GetSetListEvent;
			
			var delegate:SetDelegate = new SetDelegate(this);
			delegate.getSetList();
		}
		
		//IResponder interface methods
		public function result(event:Object) : void {
				var setList:ArrayCollection = new ArrayCollection(event.result as Array);
				ViewModelLocator.getInstance().setList = setList;
				ViewModelLocator.getInstance().error = null;
		}
		
		public function fault(event:Object) : void {
			ErrorHandler.getInstance().handleError(event as FaultEvent);
		}	
	}
}